<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Redis;
class MpaAuthMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $loginSession = $request->loginSession;
        if (!Redis::get($loginSession)){
            // 如果鉴权失败，则返回错误
            return redirect('/api/error');
        }
//        elseif(!in_array($request->path(), array_column(json_decode(Redis::get($loginSession.'route'), true), 'route'))){
//            // 如果鉴权失败，则返回错误
//            return redirect('/api/error');
//        }
        return $next($request);
    }
}
